/**
	信息总览面板
**/

Ext.onReady(function(){
	var store = new Ext.data.Store({
				proxy : new Ext.data.HttpProxy({
							url : 'dev/getDevBaseInfo.action'
						}),
				reader : new Ext.data.JsonReader({
							totalProperty : 'TOTALCOUNT',
							root : 'ROOT'
						}, [{
									name : 'id'
								}, {
									name : 'devCode'
								}, {
									name : 'devName'
								}, {
									name : 'devSpi'
								}, {
									name:'tn'
								},{
									name : 'ownUnit'
								},{
									name: 'comDate'
								}, {
									name : 'operator'
								}]),
								autoLoad:true
			});
	// 翻页排序时带上查询条件
	store.on('beforeload', function() {
				this.baseParams = {
					devSpi:Ext.getCmp("devSpiChoise").getValue(),
					ownUnit:Ext.getCmp("ownUnitChoise").getValue(),
					operator:Ext.getCmp("operatorChoise").getValue()
				};
			});	
	var pagesize_combo = new Ext.form.ComboBox({
				name : 'pagesize',
				hiddenName : 'pagesize',
				typeAhead : true,
				triggerAction : 'all',
				lazyRender : true,
				mode : 'local',
				store : new Ext.data.ArrayStore({
							fields : ['value', 'text'],
							data : [[10, '10条/页'], [20, '20条/页'],
									[50, '50条/页'], [100, '100条/页'],
									[250, '250条/页'], [500, '500条/页']]
						}),
				valueField : 'value',
				displayField : 'text',
				value : '50',
				editable : false,
				width : 85
			});
	var number = parseInt(pagesize_combo.getValue());
	pagesize_combo.on("select", function(comboBox) {
				bbar.pageSize = parseInt(comboBox.getValue());
				number = parseInt(comboBox.getValue());
				store.reload({
							params : {
								start : 0,
								limit : bbar.pageSize
							}
						});
			});
	var bbar = new Ext.PagingToolbar({
				pageSize : number,
				store : store,
				displayInfo : true,
				displayMsg : '显示{0}条到{1}条,共{2}条',
				plugins : new Ext.ux.ProgressBarPager(), // 分页进度条
				emptyMsg : "没有符合条件的记录",
				items : ['-', '&nbsp;&nbsp;', pagesize_combo]
			});
			
	var sm = new Ext.grid.CheckboxSelectionModel();
	var cm = new Ext.grid.ColumnModel([new Ext.grid.RowNumberer(), sm, {
				header : '设备ID',
				dataIndex : 'id',
				hidden:true
			}, {
				header : '设备编号',
				dataIndex : 'devCode',
				sortable : true
			}, {
				header : '设备名称',
				dataIndex : 'devName'
			}, {
				header : '设备规格',
				dataIndex : 'devSpi',
				sortable : true
			}, {
				header : '通信号码',
				dataIndex : 'tn'
			},{
				header : '归属单位',
				dataIndex : 'ownUnit',
				sortable : true
			}, {
				header : '投产日期',
				dataIndex : 'comDate',
				sortable : true
			},{
				header : '操作员',
				dataIndex : 'operator'
			}]);
	var grid = new Ext.grid.GridPanel({
				height : 510,
				store : store,
				region : 'center',
				loadMask : {
					msg : '正在加载,请稍等...'
				},
				stripeRows : true,
				frame : false,
				border:false,
				cm : cm,
				sm : sm,
				tbar : ['设备规格：',{
							xtype:'combo',
							store:new Ext.data.JsonStore({
										       fields : [
										           'devSpiCode', 'devSpiName' 
										       ],
										       url:'dev/getDevSpiList.action',
										       autoLoad:true
										   }),
							mode: 'local',
							displayField:'devSpiName',
							valueField:'devSpiCode',
							triggerAction :'all',
				            name:"devSpiChoise",
				            id:"devSpiChoise",
				            emptyText:'选择设备规格'
						}, '-','归属单位：', {
							xtype:'combo',
							store:new Ext.data.JsonStore({
										       fields : [
										           'ownUnitCode', 'ownUnitName' 
										       ],
										       url:'dev/getOwnUnitList.action',
										       autoLoad:true
										   }),
							mode: 'local',
							displayField:'ownUnitName',
							valueField:'ownUnitCode',
							triggerAction :'all',
				            name:"ownUnitChoise",
				            id:"ownUnitChoise",
				            emptyText:'选择归属单位'
						}, '-','操作员：',{
							xtype:'combo',
							store:new Ext.data.JsonStore({
										       fields : [
										           'operatorCode', 'operatorName' 
										       ],
										       root:'root',
										       url:'dev/getOperatorList.action',
										       autoLoad:true
										   }),
							mode: 'local',
							displayField:'operatorName',
							valueField:'operatorCode',
							triggerAction :'all',
				            name:"operatorChoise",
				            id:"operatorChoise",
				            emptyText:'选择操作员'
						}, '&nbsp;&nbsp;&nbsp;&nbsp;', {
							text : '查询',
							iconCls : 'previewIcon',
							handler : function() {
								store.reload({
									params:{
										devSpi:Ext.getCmp("devSpiChoise").getValue(),
										ownUnit:Ext.getCmp("ownUnitChoise").getValue(),
										operator:Ext.getCmp("operatorChoise").getValue(),
										start : 0,
										limit : bbar.pageSize
									}
								});
							}
						}, '->',{
							text : '导出为Excel',
							iconCls : 'page_excelIcon',
							handler : function() {
								downloadDevBaseInfo();
							}
						}],
				bbar : bbar
			});	
	
	function downloadDevBaseInfo(){
		var devSpi = Ext.getCmp('devSpiChoise').getValue();
		var ownUnit = Ext.getCmp('ownUnitChoise').getValue();
		var operator = Ext.getCmp('operatorChoise').getValue();
		
		var fd=Ext.get('bfrmDummy');
		
		if (!fd) {
	        fd=Ext.DomHelper.append(Ext.getBody(),{tag:'form',method:'post',id:'bfrmDummy',action:'dev/downloadDevBaseInfo.action',name:'bfrmDummy',cls:'x-hidden',cn:[
	            {tag:'input',name:'devSpi',id:'devSpi3',type:'hidden'},
	            {tag:'input',name:'ownUnit',id:'ownUnit3',type:'hidden'},
	            {tag:'input',name:'operator',id:'operator3',type:'hidden'},
	        ]},true);
	    }
	    fd.child('#devSpi3').set({value:devSpi});
	    fd.child('#ownUnit3').set({value:ownUnit});
	    fd.child('#operator3').set({value:operator});
	    fd.dom.submit();
	}
	
	/**
	 * 布局
	 */
	var viewport = new Ext.Viewport({
				layout : 'fit',
				items : [grid]
			});
});